﻿using System;
using System.Collections.Generic;
using System.Xml;
using Moonlite.ExtensionApi.XimlInterfaces;

namespace Moonlite.Platform.Ximl {
    public class XimlNodeProperties : IXimlNodeProperties {
        private Dictionary<string, string> innerProperties = new Dictionary<string, string>();
        internal Dictionary<string, string> InnerProperties {
            get { return innerProperties; }
        }
        public string this[string key] {
            get {
                lock (innerProperties) {
                    string val = null;
                    innerProperties.TryGetValue(key, out val);
                    return val;
                }
            }
            set {
                if (value == null && innerProperties.ContainsKey(key)) {
                    innerProperties.Remove(key);
                }
                if (!innerProperties.ContainsKey(key)) {
                    innerProperties.Add(key, value);
                }
                else {
                    innerProperties[key] = value;
                }
            }
        }
        public int Count {
            get { return innerProperties.Count; }
        }
        public bool ContainsKey(string key) {
            lock (innerProperties) {
                return innerProperties.ContainsKey(key);
            }
        }
        public bool ContainsValue(string value) {
            lock (innerProperties) {
                return innerProperties.ContainsValue(value);
            }
        }
    }
}
